#!/usr/bin/env python
# -*- coding: UTF8 -*-

""" docstring """

__author__      = "Hao FengGe (xxhfg@163.com)"
__version__     = "@Revision: 0.1 $"
__date__        = "@Update  : 2011/02/24 14:26:59 $"
__copyright__   = "Copyright (c) 2010 Hao FengGe"
__license__     = "Python"

from unittest import TestCase
from lottery_qxc import * 

class simpleTest(TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_get_data_from_db(self):
        """测试返回值 for test_get_data_from_db"""
        data = get_data_from_db()
        self.assertTrue(isinstance(data, (list, list)))

    def test_add_data_to_db_with_error_data(self):
        """异常数据 for test_add_data_to_db"""
        data = []
        self.assertRaises(DATA_FORMAT_ERROR, add_data_to_db, data)

    def test_parser_qxc(self):
        """正常数据 for test_parser_qxc"""
        url = 'http://www.lottery.gov.cn/lottery/qxc/History.aspx'
        status, content = get_qxc(url)
        history_list = parser_qxc(content)
        self.assertEqual(len(history_list), 50)

    def test_get_qxc(self):
        """正常数据 for test_get_qxc"""
        url = 'http://www.lottery.gov.cn/lottery/qxc/History.aspx'
        status, content = get_qxc(url)
        self.assertEqual(status, 200)
    
    def test_get_qxc_with_error_url(self):
        """异常数据 for test_get_qxc_with_error_url"""
        url = 'http://www.lottery.gov.com/lottery/qxc/History.aspx'
        self.assertRaises(HTTP_TRANS_ERROR,get_qxc,url)

if __name__ == '__main__':
    import unittest
    unittest.main()
    

